package com.kcht.np.vo.page;

import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 多条件分页查询实体，请业务人员自己去校验字段
 * */
@Accessors(chain = true)
@ToString
public class ConditionsQuery extends QueryParameter {

    private Map<String,String> conditions=new HashMap<>();
    //需要转换的字段，驼峰转为下划线，由于前端传递字段为驼峰，mysql表为下划线所以需要转换，只需在此变量中添加，当参数传递过来会自动转换
    private static Map<String,String> fieldConverter=new HashMap<String, String>(){{
        put("stationCode","station_code");
        put("inOut","in_out");
        put("reportStatus","report_status");
        put("startTime","start_time");
        put("endTime","end_time");
        put("createTime","create_time");
        put("stationDesc","station_desc");
    }};

    public Map<String, String> getConditions() {
        return conditions;
    }

    public void setConditions(Map<String, String> conditions) {
        Map<String,String> tempMap=new HashMap<>();
        Set<String> keys = conditions.keySet();
        for (String key : keys) {
            String field = fieldConverter.get(key);
            String fieldValue = conditions.get(key);
            if(field==null){
                tempMap.put(key,fieldValue);
            }else{
                tempMap.put(field,fieldValue);
            }
        }
        this.conditions = tempMap;
    }
}
